package com.ruiyangwang.ListenBook.service;

import com.ruiyangwang.ListenBook.dataObject.AlbumDO;
import com.ruiyangwang.ListenBook.dataObject.TrackDo;
import com.ruiyangwang.ListenBook.repository.AlbumRepo;
import com.ruiyangwang.ListenBook.repository.RelationRepo;
import com.ruiyangwang.ListenBook.repository.TrackRepo;
import com.ruiyangwang.ListenBook.util.Log;
import com.ruiyangwang.ListenBook.viewObject.BindView;
import com.ruiyangwang.ListenBook.viewObject.UserV0;

import java.util.ArrayList;
import java.util.List;

/**
 * @author syzygy
 * @date 2022/07/20 21:02
 **/
public class AlbumService {
    private final AlbumRepo albumRepo = new AlbumRepo();
    private final RelationRepo relationRepo= new RelationRepo();
    private final TrackRepo trackRepo = new TrackRepo();
    public Object getBindInfo(UserV0 currentUser, int aid) {
        AlbumDO albumDO = albumRepo.selectOneByUidAndAid(currentUser,aid);
        if(albumDO == null){
            throw new RuntimeException("aid 不存在或者不属于这个用户");
        }
        List<TrackDo> trackDoList;
        List<Integer> tidList = relationRepo.selectListByAid(aid);
        Log.println(tidList.toString());
        if(tidList.isEmpty()){
            trackDoList = new ArrayList<>();
        }else {
            trackDoList = trackRepo.selectListByTidList(tidList);
        }
        return new BindView(currentUser,albumDO,trackDoList);
    }
}